home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2003 June / macformat-130.iso / mac / Reviewed⁄Demos / Spearhead Demo / demota / pak1.pk3 / global / cabinet.scr < prev    next >
Encoding:
Text File  |  2002-10-21  |  5.5 KB  |  229 lines

  1. //    Cabinet Guy system created by Mackey McCandlish
  2. //    
  3. //    Before level waittill spawn "exec global/cabinet.scr".
  4. //    
  5. //    Used in m5l1a, m5l1b, and m3l2 or m3l3, or maybe both.
  6. //    
  7. //    Make a animate/furniture_hidden-cabinet (there are 3 possible kinds). Targetname it "cabinet".
  8. //
  9. //    Create an AI guy nearby. Give him classname "ai_actor" (doesn't effect anything except make his bounding box blue in the
  10. //    editor, makes him stand out as a "not real guy"). Target the cabinet to the guy.
  11. //
  12. //    Create a trigger_multiple with targetname "cabinettrigger". Give it and the cabinet the same #set value. The way it works
  13. //    is that entering the cabinettrigger arms the cabinet and leaving the cabinettrigger fires the cabinet (unleashing the AI
  14. //    guy). 
  15. //
  16. //    The default chance of a guy jumping out of a cabinet is 40%. You can change this by giving the cabinet a new #chance value.
  17.  
  18. main:
  19.     if ($cabinettrigger == NULL)
  20.         level.cabinettriggers = 0
  21.         else
  22.         level.cabinettriggers = $cabinettrigger.size
  23.  
  24.     if (level.cabinettriggers > 0)
  25.     {
  26.         level.cabinettrigger = exec global/makearray.scr $cabinettrigger
  27.  
  28.         for (local.i=1;local.i<level.cabinettriggers+1;local.i++)
  29.         {
  30.             if (level.cabinettrigger[local.i].set == NIL)
  31.                 exec global/error.scr ("Error, cabinettrigger at " + level.cabinettrigger[local.i].origin + " has no #set") 1
  32.                 else
  33.                 level.cabinettrigger[local.i] thread cabinettrigger
  34.         }
  35.  
  36.         println ("Spawned " + level.cabinettriggers + " cabinettriggers")
  37.     }
  38.  
  39.  
  40.     if ($cabinet == NULL)
  41.          level.cabinets = 0
  42.         else
  43.         level.cabinets = $cabinet.size
  44.  
  45.     if (level.cabinets > 0)
  46.     {
  47.         level.cabinet = exec global/makearray.scr $cabinet
  48.  
  49.         for (local.i=1;local.i<level.cabinets+1;local.i++)
  50.         {
  51.             if (level.cabinet[local.i].set == NIL)
  52.                 exec global/error.scr ("Error, cabinet at " + level.cabinet[local.i].origin + " has no #set") 1
  53.             else
  54.             {
  55.                 if (level.cabinet[local.i].target)
  56.                     level.cabinet[local.i].spawner = waitthread global/spawner.scr::spawner_create level.cabinet[local.i].target
  57.  
  58.                 level.cabinet[local.i] thread checkdeath
  59.                 level.cabinet[local.i] thread checkuse
  60.             }
  61.         }
  62.  
  63.         println ("Spawned " + level.cabinets + " cabinets")
  64.     }
  65. end
  66.  
  67.  
  68.  
  69. cabinettrigger:
  70.     level waittill spawn
  71.     if (game.medic != NIL)
  72.     {
  73.         self delete
  74.         end
  75.     }
  76.  
  77.     self waittill trigger
  78.     while ($player istouching self)
  79.         waitframe
  80.  
  81.     for (local.i=1;local.i<level.cabinets+1;local.i++)
  82.     if ((level.cabinet[local.i].set == self.set) && (isalive level.cabinet[local.i]))
  83.         thread cabinetgo local.i
  84.  
  85. end
  86.  
  87. cabinetgo local.i:
  88.  
  89. //    if (level.cabinet[local.i].dontfire == NIL)
  90.     local.num = randomint (100) 
  91.     level.cabinet[local.i].dontfire = 1
  92.  
  93.     if (local.num < level.cabinet[local.i].chance)
  94.     {
  95.         if (level.cabinet[local.i].pause)
  96.             wait (level.cabinet[local.i].pause)
  97.  
  98.         if (level.cabinet[local.i].target)
  99.             local.target = level.cabinet[local.i].target
  100.  
  101.         
  102.         if (level.cabinet[local.i].spawner != NIL)
  103.             local.ent = waitthread global/spawner.scr::spawner_activate level.cabinet[local.i].spawner
  104.         else
  105.             local.ent = spawn human/german_wehrmact_soldier
  106.  
  107.         level.cabinet[local.i] damage $world 15000 $world (0 0 0) (0 0 0) (0 0 0) 0 9 0 0
  108.  
  109.         if (local.target)
  110.             local.ent.creator = local.target
  111.  
  112.         local.ent.nosurprise = 1
  113.         local.ent.angles = level.cabinet[local.i].angles
  114.         local.ent noticescale 1
  115.         local.ent mindist 64
  116.         local.ent maxdist 2048
  117.         local.ent accuracy 100
  118.         local.o = level.cabinet[local.i] gettagposition "tag_origin"
  119.         local.ent.origin = local.o
  120.         local.ent exec global/disable_ai.scr
  121.         local.ent notsolid
  122.         level.cabinet[local.i] playsound cabinetopen
  123.         level.cabinet[local.i] anim open
  124.         local.ent anim_scripted cabinet_hiding_attack
  125.         local.ent waittill animdone
  126.         local.angles = vector_toangles (local.ent.origin - $player.origin)
  127.         local.ent.angles = ( 0 (local.angles[1] - 180) 0)
  128.  
  129.         local.ent exec global/enable_ai.scr
  130.         local.ent solid
  131.         wait 3
  132.         local.ent runto $player
  133.     }
  134.  
  135. end
  136.  
  137. checkuse:
  138.     level waittill spawn
  139.     if (game.medic == NIL)
  140.         self.rotatedbbox = 1
  141. end
  142.  
  143.  
  144. checkdeath:    
  145.  
  146.     self solid
  147.  
  148. //    local.target = $(self.targetname + self.target)
  149.  
  150. /*
  151.     if (self.target != NIL)
  152.     {
  153.         local.target = self.target
  154.         local.target notsolid
  155.         if (local.target.model == NIL)
  156.             local.target.model = "human/german_wehrmact_soldier.tik"
  157.         self.mdl = local.target.model
  158.         local.target.model = "fx/dummy.tik"
  159.     }
  160. */
  161.     
  162.     if !(self.chance)
  163.         self.chance = 40
  164.     
  165. //    if (randomint (100) > self.chance)
  166. //        self.dontfire = 1
  167.  
  168.     level waittill spawn
  169.  
  170.  
  171.  
  172.     self solid
  173.  
  174.     if (game.medic != NIL)
  175.     {
  176.         self delete
  177.         end
  178.     }
  179.  
  180.     self takedamage
  181.     self.health = randomint(100) + 50
  182.  
  183.  
  184.  
  185.     while (self.health > 1)
  186.         wait 0.2
  187.  
  188.  
  189.  
  190.     if (randomint (100) < self.chance)
  191.         end
  192.  
  193.     if (self.dontfire != NIL)
  194.         end
  195.  
  196.     if (self.spawner != NIL)
  197.         local.ent = waitthread global/spawner.scr::spawner_activate self.spawner
  198.     else
  199.         local.ent = spawn human/german_wehrmact_soldier
  200.  
  201.     local.ent nodamage
  202.     local.ent dontdropweapons
  203.     local.ent hide
  204.     local.ent.creator = local.target
  205.  
  206.     local.ent.angles = self.angles
  207.     local.ent noticescale 1
  208.     local.ent accuracy 100
  209.     local.o = self gettagposition "tag_origin"
  210.     local.ent.origin = local.o
  211.     local.ent exec global/disable_ai.scr
  212.     local.ent notsolid
  213.  
  214.     local.ent exec global/setdeathanim.scr "cabinet_hiding_death"
  215.  
  216.     local.ent.no_idle = 1
  217.     local.ent dropitems
  218.     local.ent anim_scripted cabinet_hiding_death
  219.  
  220.     wait 0.35
  221.     local.ent show
  222.     self playsound cabinetopen
  223.     self anim open
  224.  
  225.     local.ent waittill animdone
  226.     local.ent bedead
  227.     
  228. end
  229.